package bcc.java8.chap05;

import java.util.Arrays;
import java.util.List;
import java.util.Optional;

/**
 * .
 *
 * @author: bcc
 * 2020/11/4
 */
public class ReduceTest {
    public static void main(String[] args) {
        List<Integer> list = Arrays.asList(1,2,3,4,5);

        Optional<Integer> reduce = list.stream().reduce((a, b) -> a + b);
        System.out.println(reduce.get());
        Integer reduce1 = list.stream().reduce(0, (a, b) -> a + b);
        System.out.println(reduce1);

        Optional<Integer> reduce2 = list.stream().reduce((a, b) -> a * b);
        System.out.println(reduce2.get());
        Integer reduce3 = list.stream().reduce(1, (a, b) -> a * b);
        System.out.println(reduce3);

        Optional<Integer> reduce4 = list.stream().reduce(Integer::sum);
        System.out.println(reduce4.get());
        System.out.println(list.stream().count());
    }
}
